package com.aloda.mapper;

import com.aloda.dto.UserPageDTO;
import com.aloda.entity.User;
import com.aloda.vo.UserPageVO;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UserMapper {

    /**
     * 分页查询用户
     * @param userPageDTO
     * @return
     */
    Page<UserPageVO> pageQuery(UserPageDTO userPageDTO);

    /**
     * 新增用户
     * @param user
     */
    @Insert("INSERT INTO supermarket.users(username, password, avatarUrl, name, gender, phone, mail, create_time, update_time, authority, nickname) " +
            "VALUES (#{username}, #{password}, #{avatarUrl}, #{name}, #{gender}, #{phone}, #{mail}, #{createTime}, #{updateTime}, #{authority}, #{nickname})")
    void addUser(User user);

    @Select("select * from supermarket.users where id = #{id}")
    User getUserById(Long id);

    void update(User user);

    /**
     * 注销用户
     * @param ids
     */
    void logoutUser(List<Long> ids);

    @Select("select * from supermarket.users where username = #{username}")
    User getUserByUsername(String username);
}
